package com.yoomiito.app.widget.dialog;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.yoomiito.app.R;
import com.yoomiito.app.listener.OnViewClickListener;

public class SearchDialog extends BaseDialog implements View.OnClickListener {

    private TextView mContentTv;
    private TextView mSureTv;
    private String content;
    private OnViewClickListener mOnViewClickListener;
    public SearchDialog(@NonNull Context context) {
        this(context,0);
    }

    public SearchDialog(@NonNull Context context, int themeResId) {
        super(context, R.style.dialog_2);
    }

    protected SearchDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    public View setView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_search,null);
        mContentTv = view.findViewById(R.id.dialog_search_content);
        mContentTv.setText(content);
        mContentTv.setMovementMethod(ScrollingMovementMethod.getInstance());
        mSureTv = view.findViewById(R.id.item_sure);
        mSureTv.setText("搜索");
        mSureTv.setOnClickListener(this);
        view.findViewById(R.id.item_cancel).setOnClickListener(this);
        setCanceledOnTouchOutside(true);
        return view;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.item_cancel:
                dismiss();
                break;
            case R.id.item_sure:
                if (mOnViewClickListener!=null){
                    mOnViewClickListener.onClick(v);
                }
                break;
        }
    }

    public SearchDialog setContent(String content){
        this.content = content;
        if (mContentTv!=null){
            mContentTv.setText(content);
        }
        return this;
    }

    public String getContent(){
        return content;
    }

    public SearchDialog setOnViewClickListener(OnViewClickListener onViewClickListener) {
        mOnViewClickListener = onViewClickListener;
        return this;
    }

}
